package cn.antho.product.controller;

import cn.antho.basic.util.LoginContext;
import cn.antho.org.domain.Employee;
import cn.antho.org.mapper.EmployeeMapper;
import cn.antho.pet.dto.AcceptDto;
import cn.antho.product.dto.PrepareOrderDto;
import cn.antho.product.service.IProductOrderMsgService;
import cn.antho.product.domain.ProductOrderMsg;
import cn.antho.product.query.ProductOrderMsgQuery;
import cn.antho.basic.util.AjaxResult;
import cn.antho.basic.util.PageList;
import cn.antho.user.domain.Logininfo;
import cn.antho.user.domain.User;
import cn.antho.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/productOrderMsg")
public class ProductOrderMsgController {
    @Autowired
    public IProductOrderMsgService productOrderMsgService;


    /**
     * 保存和修改公用的
     * @param productOrderMsg  传递的实体
     * @return AjaxResult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody ProductOrderMsg productOrderMsg){
        try {
            if( productOrderMsg.getId()!=null)
                productOrderMsgService.update(productOrderMsg);
            else
                productOrderMsgService.add(productOrderMsg);
            return AjaxResult.me().success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            productOrderMsgService.delete(id);
            return AjaxResult.me().success();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    public ProductOrderMsg get(@PathVariable("id")Long id)
    {
        return productOrderMsgService.findById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<ProductOrderMsg> list(){

        return productOrderMsgService.findAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
    public PageList<ProductOrderMsg> json(@RequestBody ProductOrderMsgQuery query)
    {
        return productOrderMsgService.queryByPage(query);
    }

    @PostMapping("/state")
    public PageList<ProductOrderMsg> queryByState(@RequestBody ProductOrderMsgQuery query)
    {
        return productOrderMsgService.queryByState(query);
    }

    @PostMapping("/prepareOrder/{id}")
    public AjaxResult prepareOrder(@RequestBody @PathVariable("id") Long id, HttpServletRequest request) {
        productOrderMsgService.prepareOrder(id, request);
        return AjaxResult.me().success();
    }

    @PostMapping("/accept")
    public AjaxResult accept(@RequestBody PrepareOrderDto dto) {
        productOrderMsgService.accept(dto);
        return AjaxResult.me().success();
    }

    @PostMapping("/reject/{id}")
    public AjaxResult reject(@RequestBody @PathVariable("id") Long id) {
        productOrderMsgService.reject(id);
        return AjaxResult.me().success();
    }

}
